﻿Public Class frmSSSBR
    Private frmParent As frmMain
    Dim validator As PropertyValidator = New PropertyValidator
    'Dim sqlManager As New SQLManager
    'Dim sqlList As New SQLList
    Dim payrollManager As New PayrollManager
    Private Sub frmSSSBR_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.MdiParent = frmMain
        ClearAllFields()

        Try
            Dim sssList As List(Of SSS) = payrollManager.getAllSSS()
            For Each sss As SSS In sssList
                Dim item As ListViewItem
                item = lvwSSS.Items.Add(sss.bracket)
                item.SubItems.Add(sss.min_salary)
                item.SubItems.Add(sss.max_salary)
                item.SubItems.Add(sss.monthly_salary)
                item.SubItems.Add(sss.employer_share)
                item.SubItems.Add(sss.employee_share)
                item.SubItems.Add(sss.employee_compensation)
                item.SubItems.Add(sss.id)
            Next
            grpSSS.Text = "Total Record(s): " + lvwSSS.Items.Count.ToString()
            validator.resizes(lvwSSS)
        Catch ex As Exception
            MsgBox("Can't load Web page" & vbCrLf & ex.Message)
        End Try
    End Sub
    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        frmSSSDE.ShowDialog()
        frmSSSBR_Load(vbNull, EventArgs.Empty)
    End Sub

    Public Function ClearAllFields()
        validator.ResetControls(grpSSS)
        btnAdd.Enabled = True
        btnEdit.Enabled = False
        btnDelete.Enabled = False
        btnImport.Enabled = True
        grpSSS.Text = "Total Record(s): 0"
        validator.resizes(lvwSSS)
        Clipboard.Clear()
        Return 0
    End Function
    Private Sub lvwSSS_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvwSSS.SelectedIndexChanged
        btnEdit.Enabled = (lvwSSS.SelectedItems.Count = 1)
        btnDelete.Enabled = (lvwSSS.SelectedItems.Count > 0)
    End Sub

    Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImport.Click
        Clipboard.SetText("SSS")
        frmImport.ShowDialog()
        frmSSSBR_Load(vbNull, EventArgs.Empty)
    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        Clipboard.SetText(lvwSSS.SelectedItems(0).SubItems(7).Text)
        frmSSSDE.ShowDialog()
        frmSSSBR_Load(vbNull, EventArgs.Empty)
    End Sub
    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Try
            For i As Integer = 1 To lvwSSS.SelectedItems.Count
                'sqlManager.executeQuery("DELETE FROM tbl_sss WHERE id = " + lvwSSS.SelectedItems(i - 1).SubItems(7).Text)
                payrollManager.deleteItemSSS(lvwSSS.SelectedItems(i - 1).SubItems(7).Text)
            Next
            MsgBox("Record(s) has been deleted.")
            frmSSSBR_Load(vbNull, EventArgs.Empty)
            grpSSS.Text = "Total Record(s): " + lvwSSS.Items.Count.ToString()
        Catch ex As Exception
            MsgBox("Can't load Web page" & vbCrLf & ex.Message)
        End Try
    End Sub
End Class